﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace iS3.DAL.SQLSERVER
{
    public class DBHelp
    {
        public virtual char Pre
        {
            get
            {
                return '@';
            }
        }
        /// <summary>
        /// Sql关键字处理
        /// </summary>
        public static string Keyword(string name)
        {
            if (!string.IsNullOrEmpty(name))
            {
                name = name.Trim();
                if (name.IndexOfAny(new char[] { ' ', '[', ']', '`', '"', '(', ')' }) == -1)
                {
                    string pre = null;
                    int i = name.LastIndexOf('.');// 增加跨库支持（demo.dbo.users）
                    if (i > 0)
                    {
                        string[] items = name.Split('.');
                        pre = items[0];
                        name = items[items.Length - 1];
                    }
                    return (pre == null ? "" : pre + "..") + "[" + name + "]";
                }
            }
            return name;
        }

        
    }
}
